package com.atguigu.tingshu.account.api;

import com.atguigu.tingshu.account.service.RechargeInfoService;
import com.atguigu.tingshu.common.login.RequiresLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.account.RechargeInfo;
import com.atguigu.tingshu.vo.account.RechargeInfoVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Tag(name = "充值管理")
@RestController
@RequestMapping("api/account")
public class RechargeInfoApiController {

	private final RechargeInfoService rechargeInfoService;

	public RechargeInfoApiController(RechargeInfoService rechargeInfoService) {
		this.rechargeInfoService = rechargeInfoService;
	}

	@Operation(summary = "根据订单号获取充值信息")
	@Parameters({
			@Parameter(name = "orderNo", description = "订单号", required = true)
	})
	@GetMapping("/rechargeInfo/getRechargeInfo/{orderNo}")
	public Result<RechargeInfo> getRechargeInfo(@PathVariable String orderNo) {
		RechargeInfo rechargeInfo = this.rechargeInfoService.getRechargeInfoByOrderNo(orderNo);
		return Result.ok(rechargeInfo);
	}


	@Operation(summary = "充值余额")
	@Parameters({
			@Parameter(name = "rechargeInfoVo", description = "充值信息", required = true)
	})
	@RequiresLogin
	@PostMapping("/rechargeInfo/submitRecharge")
	public Result<Map<String, String>> submitRecharge(@RequestBody RechargeInfoVo rechargeInfoVo) {
		return Result.ok(this.rechargeInfoService.submitRecharge(rechargeInfoVo));
	}
}

